// src/design/design-page.entity.ts
import { Entity, PrimaryGeneratedColumn, Column, UpdateDateColumn, CreateDateColumn, ManyToOne, JoinColumn } from 'typeorm';
import { Category } from '../category/category.entity';

@Entity('design_pages')
export class DesignPage {
  @PrimaryGeneratedColumn()
  id: number;

  @Column({ length: 255 })
  title: string;

  @Column({ type: 'longtext' })
  content: string;

  @CreateDateColumn()
  createdAt: Date;

  @UpdateDateColumn()
  updatedAt: Date;

  @Column()
  category_id: number;

  @Column({ nullable: true })
  cover_img: string;

  @Column({ type: 'json', nullable: true }) // 新增：图片数组（JSON格式存储）
  cover_images: Record<string, any>; // 或直接使用 `object`

  @Column({ length: 300, nullable: true })
  summary: string;

  // @ManyToOne(() => Category, (category) => category.pages)
  @ManyToOne(() => Category, (category) => category.pages, { onDelete: 'CASCADE' }) // 级联删除可选
  @JoinColumn({ name: 'category_id' })
  category: Category;

  @Column({ default: true }) // 新增：控制文章是否显示
  is_visible: boolean;

  @Column({ default: 100 })
  percentage: number; // 文章显示百分比（可选）
}